home *** CD-ROM | disk | FTP | other *** search
- #
- # process.test
- #
- # Tests for the fork, execl and wait commands.
- #---------------------------------------------------------------------------
- # Copyright 1992 Karl Lehenbauer and Mark Diekhans.
- #
- # Permission to use, copy, modify, and distribute this software and its
- # documentation for any purpose and without fee is hereby granted, provided
- # that the above copyright notice appear in all copies. Karl Lehenbauer and
- # Mark Diekhans make no representations about the suitability of this
- # software for any purpose. It is provided "as is" without express or
- # implied warranty.
- #------------------------------------------------------------------------------
- # $Id: process.test,v 2.0 1992/10/16 04:50:05 markd Rel $
- #------------------------------------------------------------------------------
- #
-
- if {[info procs test] != "test"} then {source testlib.tcl}
-
- # Proc to fork and exec child that loops until it gets a signal.
-
- proc ForkLoopingChild {{setPGroup 0}} {
- flush stdout
- flush stderr
- set newPid [fork]
- if {$newPid != 0} {
- return $newPid
- }
- if $setPGroup {
- id process group set
- }
- execl ../tcl {-qc {catch {while {1} {sleep 1}}; exit 10}}
- error "Should never make it here"
- }
-
-
- # Test fork, execl, and wait commands.
-
- Test process-1.1 {fork, execl, wait tests} {
- set newPid [fork]
- if {$newPid == 0} {
- execl ../tcl {-qc {sleep 1;exit 12}}
- error "Should never make it here"
- }
- lrange [wait $newPid] 1 end
- } 0 {EXIT 12}
-
- Test process-1.2 {fork, execl, wait tests} {
- set newPid [ForkLoopingChild]
- sleep 1
-
- kill $newPid
- lrange [wait $newPid] 1 end
- } 0 {SIG SIGTERM}
-
- set newPid1 [ForkLoopingChild]
- set newPid2 [ForkLoopingChild]
-
- Test process-1.3 {fork, execl, wait tests} {
- sleep 3 ;# Give em a chance to get going.
-
- kill [list $newPid1 $newPid2]
-
- list [wait $newPid1] [wait $newPid2]
-
- } 0 [list "$newPid1 SIG SIGTERM" "$newPid2 SIG SIGTERM"]
-
- Test process-1.4 {fork, execl, wait tests} {
- fork foo
- } 1 {wrong # args: fork}
-
- Test process-1.5 {fork, execl, wait tests} {
- wait baz
- } 1 {expected integer but got "baz"}
-
- Test process-1.6 {fork, execl, wait tests} {
- set testPid [ForkLoopingChild]
- kill $testPid
- set result [wait $testPid]
- lrange $result 1 end
- } 0 {SIG SIGTERM}
-
- # Test extended wait functionality, if available.
-
- catch {wait -nohang 1} result
- if {$result == "wrong # args: wait pid"} return
-
- Test process-2.1 {fork, execl, wait tests} {
- set testPid [ForkLoopingChild]
- set result1 [wait -nohang $testPid]
- kill $testPid
- set result2 [wait $testPid]
- list $result1 [lrange $result2 1 end]
- } 0 {{} {SIG SIGTERM}}
-
- Test process-2.2 {fork, execl, wait tests} {
- set testPid [ForkLoopingChild 1]
- set result1 [wait -nohang -pgroup $testPid]
- kill $testPid
- set result2 [wait -pgroup $testPid]
- list $result1 [lrange $result2 1 end]
- } 0 {{} {SIG SIGTERM}}
-
- Test process-2.3 {fork, execl, wait tests} {
- set testPid [ForkLoopingChild]
- set result1 [wait -nohang -pgroup -untraced $testPid]
- kill $testPid
- set result2 [wait -pgroup -untraced $testPid]
- list $result1 [lrange $result2 1 end]
- } 0 {{} {SIG SIGTERM}}
-
-
-